package db.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.db.BeanBase;
import com.db.Table;

import db.beans.T_RankingBean;


public class T_RankingTable extends Table{
	
	public static final String COL_KEY_WORLD_NO = "KEY_WORLD_NO";
	public static final String COL_KEY_WORLD = "KEY_WORLD";
	public static final String COL_RANK = "RANK";
	
	public static BeanBase[] selectAll(Connection conn, String strTableName) throws SQLException{
		final String sql = "SELECT " 
			+ COL_KEY_WORLD_NO + ","
			+ COL_KEY_WORLD + "," 
			+ COL_RANK
			+ " FROM " + strTableName;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<T_RankingBean> v = new Vector<T_RankingBean>();
		try {
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			int i;
			while (rs.next()) {
				i = 0;
				T_RankingBean rec = new T_RankingBean();
				rec.setKeyWorldNo(rs.getInt(++i));
				rec.setKeyWorld(rs.getString(++i));
				rec.setRank(rs.getInt(++i));
				v.add(rec);
			}
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
		}
		return (T_RankingBean[]) v.toArray(new T_RankingBean[v.size()]);
	}
	
}
